package GameObjects;

import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.World;
import org.mt4j.MTApplication;
import org.mt4j.util.math.Vector3D;

import Controller.Player;
import advanced.physics.physicsShapes.PhysicsCircle;

import processing.core.PApplet;

public class GameBall extends PhysicsCircle {
	
	private Player playerAffinity;

	public GameBall(MTApplication app, Vector3D centerPoint, float radius,
			World world, float worldScale) {
		
		super(app, centerPoint, radius, world, 1, 0, 1f, worldScale);

		this.unregisterAllInputProcessors();		
	}
	
	public void handleVelocity( float maxVelocity ) {
		float maxVeloFactor = 10 / maxVelocity;		
		Vec2 old = this.getBody().getLinearVelocity();
				
		if(old.x > maxVelocity || old.y > maxVelocity)
			this.getBody().setLinearVelocity( new Vec2(old.x/maxVeloFactor, old.y/maxVeloFactor) );
		else if(old.length() < 2)
			this.getBody().setLinearVelocity( old.mul(2) );
	}

	/**
	 * 
	 * Method to keep the physicshape of the infobox rigid and avoid the wild curving around the Touchpoint.
	 * Also added the frictioneffekt with lineardamping the velocityforce.
	 * 
	 */
	protected void bodyDefB4CreationCallback(BodyDef def) 
	{
		super.bodyDefB4CreationCallback(def);
		def.linearDamping = 0f;
		def.angularDamping = 0f;
		def.isBullet = true;
	}
	
	public Player getPlayerAffinity() {
		return playerAffinity;
	}

	public void setPlayerAffinity(Player _playerAffinity) {
		playerAffinity = _playerAffinity;
	}
	
}
